\label{chapter::implementation}
\section{Parser and Scanner}
\label{section:ParserandScanner}
For the parser and scanner in CLUBs we used the tool Coco/R\cite{coco1}, which is a tool that can take an EBNF slightly changed to a format called ATG, and create a scanner and a parser. The ATG is an EBNF that contains extra information crucial to building a parser, these parts while be explained in greater detail in this section. Coco/R is able generate the scanner and parser in several programming languages, for this project we chose C\#.\\
%Scanner
The ATG also contains a list of tokens\footnote{ident, number and scope are tokens explicit declared in CLUBs} and the characters which are allowed in the language along with a list of characters that should be ignored, e.g. tab new lines etc. But not all tokens need to be explicit declared. All the tokens declared in the EBNF, they are marked with bold text in section \ref{EBNF}, are automatically added to the list of tokens. Coco/R knows it supposed to add a token by looking for words in quotation marks e.g. "game". Coco/R have implemented the scanner as a deterministic finite automaton (DFA)\cite{coco2}.\\

%arser and ll(1)
Coco/R generated a recursive descent parser which is a commonly used top-down parser easily translated from a Context-free grammar (CFG). Before generating the parser it is recommended to eliminate left recursion and left factorize if possible. In principle the grammar used in Coco/R must be on LL(1) meaning the parser will parse the input left to right and construct a leftmost derivation tree. But Coco/R handles grammar that are not in form of LL(1) by using multi-symbol look ahead or on semantic information. When building the parse three from an ATG it is possible to pad information on to the tree by writing code, in our case, C\# code in between "(." and ".)". A simple example of code padding is when parsing a Library or a Game the parser looks at the token and depending on the case set a Boolean in the AST to true or false. If we look at the Library the code looks like this:
\begin{lstlisting}
(. ast.IsLibrary = true; .)
\end{lstlisting}
%External references
The last thing we need to specify in the ATG is external references, that being references to other files or objects outside of the parser and scanner, in our case the AST and the identification table (IDT).
